package samples

import kotlinx.serialization.Serializable
import kotlinx.serialization.decodeFromString
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import org.junit.Test

/**
 *
 * @author mph
 * @date 2025/1/17
 */
class SerializationTest {

    @Test
    fun test() {
        val json = Json.encodeToString(Person("mph", 18))
        val perArray = arrayListOf(Person("mph", 18), Person("mph", 18))
        val json2 = Json.encodeToString(perArray)
        val person = Json.decodeFromString<Person>(
            """
                {"age":31, "name": "mph"}
            """.trimIndent()
        )
        println(json)
        println(json2)
        println(person)
    }

}

@Serializable //必须加
data class Person(val name: String, val age: Int)